**********************************

*SOCIAL BASES OF POLITICAL PARTIES -- A NEW MEASURE AND SURVEY. British Journal of Political Science (2022)
*Gary Marks, David Attewell, Liesbet Hooghe, Jan Rovny, Marco Steenbergen*

**********************************
/*Introduction -- dataset creation
1. Figure 1
2. Figure 2
3. Figure 3: Alford index
4. Figure 4
5. Appendix
- descriptives
- models D.1, D.2, D.3 + figures
- breaking down GAL, religious, left: E.1
- alternative operationalizations of occupation, religion, education: E.2 + figures


*****************************
*Introduction -- dataset creation
*****************************


Eurobarometer data 1975-1995: 
Source: Mannheim data archive GESIS
use "ZA3521_v2-0-1.dta" 

European Election survey data 1994-2019: 
Source: http://europeanelectionstudies.net/
merge "EES_trend_1989 2004_data.dta", "EES_2009.dta", "EES_2014.dta", "EES_2019.dta"

European Social Survey 2002-2018
Source: https://www.europeansocialsurvey.org/
use cumulative file "ESS1-9.dta"

-Aggregate each of these to the party level (using collapse command) 
-Stack the three datasources by country, year, party label 
save "EBESSEEScombined.dta"
-Add information on party family
Source: https://chesdata.eu
use "1999-2019_CHES_dataset_means(v2).dta" file"
save "EBESSEEScombined.dta"
*/


****************************************************************************

****FIGURES 1 AND 2: FOR EU-9 countries (except Lux) + all other ESS countries (total = 20) from 2002

/*======================================================================*/
use "EBESSEES_Pfigures.dta"

*a) occupation and religion*

twoway (scatter occ1a100 mean_occ1a100 if max_n>30 & (family==5| family2==6) [aweight = vote5], mcolor(red%40) msize(small) msymbol(circle)) /// 
if EU9==1 & (year_adj2==1975), /// 
ytitle(BEHAVIOR) ylabel(0(20)80, angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)80, format(%9.1g) grid) title(SOCIAL-DEMOCRATS 1975) legend(off) clegend(off) //saving(LEFT1a.gph, replace) 

twoway (scatter occ1a100 mean_occ1a100 if max_n>30 & (family==5| family2==6) & EBESSEES==2 & year_adj2==2002 & EU9!=1 [aweight = vote5], mcolor(red%60) msize(small) msymbol(circle_hollow)) ///
(scatter occ1a100 mean_occ1a100 if max_n>30 & (family==5| family2==6) & EU9==1 & year_adj2==2002 & EBESSEES==2 [aweight = vote5], mcolor(red%40) msize(small) msymbol(circle)), //////
ytitle(BEHAVIOR) ylabel(0(20)80, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)80, format(%9.1g) grid) /// 
title(SOCIAL-DEMOCRATS 2002) legend(off) clegend(off) saving(LEFT2a.gph, replace) 

twoway (scatter occ1a100 mean_occ1a100 if max_n>30 & (family==5| family2==6) & EBESSEES==2 & year_adj2==2018 & EU9!=1 [aweight = vote5], mcolor(red%60) msize(small) msymbol(circle_hollow)) ///
(scatter occ1a100 mean_occ1a100 if max_n>30 & (family==5| family2==6) & EU9==1 & year_adj2==2018 [aweight = vote5], mcolor(red%40) msize(small) msymbol(circle)), //////
ytitle(BEHAVIOR) ylabel(0(20)80, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)80, format(%9.1g) grid) /// 
title(SOCIAL-DEMOCRATS 2018) legend(off) clegend(off) saving(LEFT3a.gph) 

twoway (scatter religio6100 mean_religio6100 if max_n>30 & (family==4| family==10) [aweight = vote5], mcolor(purple%40) msize(small) msymbol(circle)) /// 
if EU9==1 & (year_adj2==1975), /// 
ytitle(BEHAVIOR) ylabel(0(20)80, angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)80, format(%9.1g) grid) title(CHRISTIAN-DEMOCRATS 1975) legend(off) clegend(off) saving(CD1a.gph, replace) 

twoway (scatter religio6100 mean_religio6100 if max_n>30 & (family==4| family==10) & EBESSEES==2 & year_adj2==2002 & EU9!=1 [aweight = vote5], mcolor(purple%60) msize(small) msymbol(circle_hollow)) ///
(scatter religio6100 mean_religio6100 if max_n>30 & (family==4| family==10) & EU9==1 & year_adj2==2002 [aweight = vote5], mcolor(purple%40) msize(small) msymbol(circle)), ///
ytitle(BEHAVIOR) ylabel(0(20)80, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)80, format(%9.1g) grid) /// 
title(CHRISTIAN-DEMOCRATS 2002) legend(off) clegend(off) saving(CD2a.gph, replace) 

twoway (scatter religio6100 mean_religio6100 if max_n>30 & (family==4| family==10) & EBESSEES==2 & year_adj2==2018 & EU9!=1 [aweight = vote5], mcolor(purple%60) msize(small) msymbol(circle_hollow)) ///
(scatter religio6100 mean_religio6100 if max_n>30 & (family==4| family==10) & EU9==1 & year_adj2==2018 [aweight = vote5], mcolor(purple%40) msize(small) msymbol(circle)), //////
ytitle(BEHAVIOR) ylabel(0(20)80, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)80, format(%9.1g) grid) /// 
title(CHRISTIAN-DEMOCRATS 2018) legend(off) clegend(off) saving(CD3a.gph, replace) 

grc1leg LEFT1a.gph LEFT2a.gph LEFT3a.gph CD1a.gph CD2a.gph CD3a.gph, rows(2) comm ycom xcom
/*figure 1*/

/*STATS*/
tabstat occ1a_dif if max_n>30 & (family2==5| family2==6) & (year==1975| year_adj==2002 | year_adj==2018), stats (mean N) by (year)   
tabstat mean_occ1a occ1a occ1a_dif if max_n>30 & (family2==5| family2==6) & (year==1975| year_adj2==2002| year_adj2==2018) & EU9==1, stats (mean N) by (year_adj2) 
tabstat mean_occ1a occ1a occ1a_dif if max_n>30 & (family2==5| family2==6) & (year_adj2==2002 | year_adj2==2018) & EU9==1 & EBESSEES==2, stats (mean N) by (year_adj2)  
tabstat mean_occ1a occ1a occ1a_dif if max_n>30 & (family2==5| family2==6) & (year_adj2==2002 | year_adj2==2018) & EBESSEES==2, stats (mean N) by (year_adj2)   

format %9.2f mean_occ1a occ1a occ1a_dif 
sort occ1a_dif
list country party family2 party_name vote mean_occ1a occ1a occ1a_dif if max_n>30 & (family2==5| family2==6)	& year_adj2==1975 &	EU9==1,	noobs	clean
gsort -EU9 occ1a_dif
list EU9 country party family2 party_name vote mean_occ1a occ1a occ1a_dif if max_n>30 & (family2==5| family2==6)	& year_adj2==2002 & EBESSEES==2,	noobs	clean
list EU9 country party family2 vote mean_occ1a occ1a occ1a_dif if max_n>30 & (family2==5| family2==6)	& year_adj2==2018 &	EBESSEES==2,	noobs	clean

tabstat mean_religio6 religio6 religio6_dif if max_n>30 & (family==4| family==10) & (year_adj2==1975| year_adj2==2002 | year_adj2==2018) & EU9==1, stats (mean N) by (year_adj2)   
tabstat mean_religio6 religio6 religio6_dif if max_n>30 & (family==4| family==10) & (year_adj2==2002 | year_adj2==2018) & EU9==1 & EBESSEES==2, stats (mean N) by (year_adj2)   
tabstat mean_religio6 religio6 religio6_dif if max_n>30 & (family==4| family==10) & (year_adj2==2002 | year_adj2==2018) & EBESSEES==2, stats (mean N) by (year_adj2)   

format %9.2f mean_religio6 religio6 religio6_dif 
sort religio6_dif
list country party family2 party_name vote mean_religio6 religio6 religio6_dif  if max_n>30 & (family2==4| family2==10)	& year_adj2==1975 &	EU9==1,	noobs	clean
gsort -EU9 religio6_dif
list EU9 country party family2  vote mean_religio6 religio6 religio6_dif if max_n>30 & (family2==4| family2==10)	& year_adj2==2002 & EBESSEES==2,	noobs	clean
list EU9 country party family2 vote mean_religio6 religio6 religio6_dif if max_n>30 & (family2==4| family2==10)	& year_adj2==2018 &	EBESSEES==2,	noobs	clean


*b) education -- gal and tan*

twoway (scatter higher100 mean_higher100 if max_n>30 & (family2==7| family2==12| family2==13) [aweight = vote5], mcolor(green%40) msize(medsmall) msymbol(circle)) /// 
if EU9==1 & (year_adj2==1985), /// 
ytitle(BEHAVIOR) ylabel(0(20)60, angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)60, format(%9.1g) grid) title(GAL PARTIES 1985) legend(off) clegend(off) saving(GAL1a.gph, replace)

twoway (scatter higher100 mean_higher100 if max_n>30 & (family2==7| family2==12| family2==13) & EBESSEES==2 & year_adj2==2002 & EU9!=1 [aweight=vote5], mcolor(green%60) msize(medsmall) msymbol(circle_hollow)) ///
(scatter higher100 mean_higher100 if max_n>30 & (family2==7| family2==12| family2==13) & EU9==1 & year_adj2==2002  & EBESSEES==2 [aweight=vote5], mcolor(green%40) msize(medsmall) msymbol(circle)), ///
ytitle(BEHAVIOR) ylabel(0(20)60, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)60, format(%9.1g) grid) /// 
title(GAL PARTIES 2002) legend(off) clegend(off) saving(GAL2a.gph, replace)

twoway (scatter higher100 mean_higher100 if max_n>30 & (family2==7| family2==12| family2==13) & EBESSEES==2 & year_adj2==2018 & EU9!=1 [aweight = vote5], mcolor(green%60) msize(medsmall) msymbol(circle_hollow)) ///
(scatter higher100 mean_higher100 if max_n>30 & (family2==7| family2==12| family2==13) & EU9==1 & year_adj2==2018 [aweight = vote5], mcolor(green%40) msize(medsmall) msymbol(circle)), //////
ytitle(BEHAVIOR) ylabel(0(20)60, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)60, format(%9.1g) grid) /// 
title(GAL PARTIES 2018) legend(off) clegend(off) saving(GAL3a.gph, replace)

twoway (scatter higher100 mean_higher100 if max_n>30 & (family2==1) [aweight = vote5], mcolor(dkorange%40) msize(medsmall) msymbol(circle)) /// 
if EU9==1 & (year_adj2==1985), /// 
ytitle(BEHAVIOR) ylabel(0(20)60, angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)60, format(%9.1g) grid) title(TAN PARTIES 1985) legend(off) clegend(off) saving(TAN1a.gph, replace)

twoway (scatter higher100 mean_higher100 if (max_n>30) & (family2==1) & EBESSEES==2 & year_adj2==2002 & EU9!=1 [weight=vote5] , mcolor(dkorange%60) msize(medlarge) msymbol(circle_hollow)) ///
(scatter higher100 mean_higher100 if (max_n>30| party_id==112) & (family2==1) & EU9==1 & year_adj2==2002  & EBESSEES==2 [weight=vote5], mcolor(dkorange%40) msize(medlarge) msymbol(circle)), //////
ytitle(BEHAVIOR) ylabel(0(20)60, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)60, format(%9.1g) grid) /// 
title(TAN PARTIES 2002) legend(off) clegend(off) saving(TAN2a.gph, replace)

twoway (scatter higher100 mean_higher100 if (max_n>30) & (family2==1) & EBESSEES==2 & year_adj2==2018 & EU9!=1 [aweight = vote5] , mcolor(dkorange%60) msize(medsmall) msymbol(circle_hollow)) ///
(scatter higher100 mean_higher100 if (max_n>30| party_id==112) & (family2==1) & EU9==1 & year_adj2==2018  & EBESSEES==2 [aweight = vote5], mcolor(dkorange%40) msize(medsmall) msymbol(circle)), //////
ytitle(BEHAVIOR) ylabel(0(20)60, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xtitle(STRUCTURE) xlabel(0(20)60, format(%9.1g) grid) /// 
title(TAN PARTIES 2018) legend(off) clegend(off) saving(TAN3a.gph, replace) 


grc1leg GAL1a.gph GAL2a.gph GAL3a.gph TAN1a.gph TAN2a.gph TAN3a.gph, rows(2) comm ycom xcom
/*figure 2*/

/*STATS*/
/*party_id=9301 is UK SLD which is absorbed in Alliance*/
tabstat mean_higher higher higher_dif if max_n>30 & (family2==7| family2==12| family2==13) & (year_adj2==1985| year_adj2==2002 | year_adj2==2018) & EU9==1 & party_id!=9301, stats (mean N) by (year_adj2)   
tabstat mean_higher higher higher_dif if max_n>30 & (family2==7| family2==12| family2==13) & (year_adj2==2002 | year_adj2==2018) & EU9==1 & EBESSEES==2, stats (mean N) by (year_adj2)   
tabstat mean_higher higher higher_dif if max_n>30 & (family2==7| family2==12| family2==13) & (year_adj2==2002 | year_adj2==2018) & EBESSEES==2, stats (mean N) by (year_adj2)   

format %9.2f mean_higher higher higher_dif 
sort higher_dif
list country party family2 party_name vote mean_higher higher higher_dif  if max_n>30 & (family2==7| family2==12| family2==13)	& year_adj2==1985 &	EU9==1,	noobs	clean
gsort -EU9 higher_dif
list EU9 country party family2 vote mean_higher higher higher_dif if max_n>30 & (family2==7| family2==12| family2==13)	& year_adj2==2002 & EBESSEES==2,	noobs	clean
list EU9 country party family2 vote mean_higher higher higher_dif if max_n>30 & (family2==7| family2==12| family2==13)	& year_adj2==2018 &	EBESSEES==2,	noobs	clean

tabstat mean_higher higher higher_dif if max_n>30 & (family2==1) & (year_adj2==1985| year_adj2==2002 | year_adj2==2018) & EU9==1, stats (mean N) by (year_adj2)   
tabstat mean_higher higher higher_dif if (max_n>30| party_id==112) & (family2==1) & (year_adj2==2002 | year_adj2==2018) & EU9==1 & EBESSEES==2, stats (mean N) by (year_adj2)   
tabstat mean_higher higher higher_dif if (max_n>30| party_id==112) & (family2==1) & (year_adj2==2002 | year_adj2==2018) & EBESSEES==2 , stats (mean N) by (year_adj2)   

format %9.2f mean_higher higher higher_dif 
sort higher_dif
list country party family2 party_name vote mean_higher higher higher_dif  if max_n>30 & (family2==1)	& year_adj2==1985 &	EU9==1,	noobs	clean
gsort -EU9 higher_dif
list EU9 country party family2 vote mean_higher higher higher_dif if max_n>30 & (family2==1)	& year_adj2==2002 & EBESSEES==2,	noobs	clean
list EU9 country party family2 vote mean_higher higher higher_dif if (max_n>30| party_id==112) & (family2==1)	& year_adj2==2018 &	EBESSEES==2,	noobs	clean


 *****************************************************************************************************************************
** FIGURE 3: P-Behavior, P-Structure and the Alford index for the working class in three countries

**********************************************************************************************************************
/*create "Alford.dta" with Alford data vs. P data for left parties in NL, D, and UK at specific time points; this combines Eurobarometer and ESS*/

use "alford.dta"

twoway (tsline vote if party=="1"| party=="3"| party=="4", recast(area) fcolor(gs14%90) lcolor(none)) (tsline alford if party=="1"| party=="3"| party=="4", lcolor(gs6) lwidth(medium)) (tsline behavior if party=="1"| party=="3"| party=="4", lcolor(green) lwidth(medium) lpattern(vshortdash)) (tsline structure if party=="1"| party=="3"| party=="4", lcolor(green) lwidth(medthick) lpattern(longdash_dot)), ylabel(0(10)70, labsize(small) angle(horizontal)) tlabel(1975(5)2020) by(country, style(compact) cols(1)) // vote || alford || P-behavior || P-structure


****************************************************************************
*4. FIGURE 4: The effect of party family and party size on the P-score
****************************************************************************
use "EBESSEES_model.dta"

*EES and ESS data -- ESS and EES data, more robust to particularities of dataset (except for occupation -- no EES data) -- use this for main graphs and main tables

reg occ1a_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xlab(1 "TAN" 2"Con" 3"Lib" 4"CD" 5"SD" 6"GAL") xti("") ///
title(OCCUPATION) saving(occupvote.gph, replace)

reg religio6_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2|EBESSEES==3) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)40, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xlab(1 "TAN" 2"Con" 3"Lib" 4"CD" 5"SD" 6"GAL") xti("") ///
title(RELIGION) saving(religiovote.gph, replace)

reg higher_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2|EBESSEES==3) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) xlab(1 "TAN" 2"Con" 3"Lib" 4"CD" 5"SD" 6"GAL") xti("") ///
title(EDUCATION) saving(eduvote.gph, replace)

/*figure 4 in paper*/
graph combine occupvote.gph religiovote.gph eduvote.gph, rows(1) 
grc1leg occupvote.gph religiovote.gph eduvote.gph, leg(eduvote.gph) pos(6) span rows(1)


****************************
*5. ONLINE APPENDIX
****************************

*APPENDIX A. 
*Data A.1
use "EBESSEES_Pfigures.dta"
tabstat party_id max_n if EBESSEES==1 & (year==1975| year==1985) & EU9==1, stats (sum N) // for # respondents
tabstat party_id max_n if EBESSEES==1 & (year==1975| year==1985) & EU9==1 & max_n>30, stats (sum N) // for # parties meeting threshold

tabstat party_id max_n if EBESSEES==2 & (year_adj2==2002| year_adj2==2018), stats (sum N) // for # respondents
tabstat party_id max_n if EBESSEES==2 & (year_adj2==2002| year_adj2==2018) & max_n>30, stats (sum N) // for # parties meeting threshold

use "EBESSEES_model.dta"
tabstat party_id max_n if EBESSEES==2 & year>2000, stats (sum N) // for # respondents
tabstat party_id max_n if EBESSEES==2 & year>2000 & max_n>30, stats (sum N) // for # parties meeting threshold
tabstat party_id max_n if EBESSEES==3 & year>2000, stats (sum N) // for # respondents
tabstat party_id max_n if EBESSEES==3 & year>2000 & max_n>30, stats (sum N) // for # parties meeting threshold

*A.5: descriptives on party family*
tab family6 EBESSEES if max_n>30 & year!=1989

****************
*APPENDIX C3. DESCRIPTIVES
******************
use "EBESSEES_model.dta"
*C.1: p-SCORES by party family 2002-2019*
tabstat occ1a_dif100 religio6_dif100 higher_dif100 if max_n>30 & year>2000 & (EBESSEES==2|EBESSEES==3), stats (mean p50 sd N) by (family6)

*C.2: p-score trajectories for eight EU MS
by decade, sort: tabstat occ1a_dif100 if max_n>30 & EU9==1 & family6<8, stats (mean N) by (family6)
by decade, sort: tabstat religio6_dif100 if max_n>30 & EU9==1 & family6<8, stats (mean N) by (family6)
by decade, sort: tabstat higher_dif100 if max_n>30 & EU9==1 & family6<8, stats (mean N) by (family6)

*******************
*APPENDIX D: ANALYSES FOR FIGURE 4: PARTY FAMILY BY PARTY SIZE
******************
 *Model tables: D.1-D.3 
************************

***********************************************
/*OCCUPATION*/
*Table D. 1
***********************************************
/*model1: interaction with dummy*/
reg occ1a_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(OCCUPATION) saving(occupvote.gph, replace)

/*model2:interaction with continuous vote*/
reg occ1a_dif100 ib5.family6##c.vote ENEP turnout i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id)
margins family6, at(vote=(5 10 15 20)) vsquish
mplotoffset, offset (0.2) recast (scatter) xdimension(family6)

/*model3: bivariate model*/
reg occ1a_dif100 ib5.family6 if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id) // bivariate model 1
estat ic

/*model 4: country and year and survey fixed effects*/
reg occ1a_dif100 ib5.family6 i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id) // bivariate model 1
estat ic

/*model5: full controls*/
/*fixed effects + ENEP + turnout + vote*/
reg occ1a_dif100 ib5.family6 ENEP turnout vote i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id) // full
estat ic

/*model6: bootstrapping*/
reg occ1a_dif100 ib5.family6 ENEP turnout vote i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, vce (bootstrap, cl(party_id)) // bootstrap
estat ic

/*model7: Jackknife*/
reg occ1a_dif100 ib5.family6 ENEP turnout vote i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, vce (jackknife, cl(party_id)) // jackknife
estat ic

********************
/*RELIGION*/
*Table D.2.
********************
/*model1: interaction with dummy*/
reg religio6_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2|EBESSEES==3) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)40, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(RELIGION) saving(religiovote.gph, replace)

/*model2:interaction with continuous vote*/
reg religio6_dif100 ib5.family6##c.vote ENEP turnout i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2|EBESSEES==3) & year>2000, cl(party_id)
margins family6, at(vote=(5 10 15 20)) vsquish
mplotoffset, offset (0.2) recast (scatter) xdimension(family6)

/*model3: bivariate model*/
reg religio6_dif100 ib5.family6 if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, cl(party_id) // bivariate model 1
estat ic

/*model 4: country and year and survey fixed effects*/
reg religio6_dif100 ib5.family6 i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, cl(party_id) // bivariate model 1
estat ic

/*model5: full controls*/
/*fixed effects + ENEP + turnout + vote*/
reg religio6_dif100 ib5.family6 ENEP turnout vote i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, cl(party_id) // full
estat ic

/*model6: bootstrapping*/
reg religio6_dif100 ib5.family6 ENEP turnout vote i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, vce (bootstrap, cl(party_id)) // bootstrap
estat ic

/*model7: Jackknife*/
reg religio6_dif100 ib5.family6 ENEP turnout vote i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, vce (jackknife, cl(party_id)) // jackknife
estat ic

**********
*EDUCATION 
* Table (D. 3)
***********



*****
/*model1: interaction with dummy*/
reg higher_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2|EBESSEES==3) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(EDUCATION) saving(eduvote.gph, replace)

/*model2:interaction with continuous vote*/
reg higher_dif100 ib5.family6##c.vote ENEP turnout i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2|EBESSEES==3) & year>2000, cl(party_id)
margins family6, at(vote=(5 10 15 20)) vsquish
mplotoffset, offset (0.2) recast (scatter) xdimension(family6)

reg higher_dif100 ib5.family6##ib2.vote_dich ENEP turnout i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2|EBESSEES==3) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid)

/*model3: bivariate model*/
reg higher_dif100 ib5.family6 if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, cl(party_id) // bivariate model 1
estat ic

/*model 4: country and year and survey fixed effects*/
reg higher_dif100 ib5.family6 i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, cl(party_id) // bivariate model with fixed effects
estat ic

/*model5: full controls*/
*fixed effects + ENEP  + turnout  + vote
reg higher_dif100 ib5.family6 ENEP turnout vote i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, cl(party_id) // full controls
estat ic

/*model6: bootstrapping*/
reg higher_dif100 ib5.family6 ENEP turnout vote i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, vce (bootstrap, cl(party_id)) // bootstrap
estat ic

/*model7: Jackknife*/
reg higher_dif100 ib5.family6 ENEP turnout vote i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2| EBESSEES==3) & year>2000, vce (jackknife, cl(party_id)) // jackknife
estat ic



****************************************************

*APPENDIX E.1 ROBUSTNESS: Party family refined breaking down GAL and LEFT and RELIGIOUS (TABLE E.1 AND FIGURE E.1)

****************************************************

/*gen family7=family2 if family2<5
replace family7=15 if (family2==8| family2==9| family2==11)
replace family7=9 if family2==12
replace family7=10 if family2==13
replace family7=8 if family2==7
replace family7=7 if family2==6
replace family7=6 if family2==5
replace family7=5 if family2==10
label define family7 1 "TAN" 2 "Cons" 3 "Econ Libs" 4 "Christ-dems" 5 "Confes" 6 "Soc-dems" 7 "Trad-left"  8 "Green" 9 "Soc libs" 10 "New-left" 15 "other", replace
label values family7 family7
*/

reg occ1a_dif100 ib6.family7##ib2.vote_dich10 ENEP turnout i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id)
margins, at (family7=(1 2 3 4 5 6 7 8 9 10) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(OCCUPATION) saving(occupvotefamily7.gph, replace)


reg religio6_dif100 ib6.family7##ib2.vote_dich10 ENEP turnout i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2|EBESSEES==3) & year>2000, cl(party_id)
margins, at (family7=(1 2 3 4 5 6 7 8 9 10) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)70, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(RELIGION) saving(religiovotefamily7.gph, replace)


reg higher_dif100 ib6.family7##ib2.vote_dich10 ENEP turnout i.country i.year i.EBESSEES if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2|EBESSEES==3) & year>2000, cl(party_id)
margins, at (family7=(1 2 3 4 5 6 7 8 9 10) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(EDUCATION) saving(eduvotefamily7.gph, replace)


grc1leg occupvotefamily7.gph religiovotefamily7.gph eduvotefamily7.gph, leg(eduvotefamily7.gph) pos(6) span cols(1) // FIGURE E.1

*************************************************************

*APPENDIX E.2 ROBUSTNESS: alternative dichotomizations -- because of operationalization incompatibilities, limit to ESS
*(TABLE E.2 AND FIGURE E.2)
*************************************************************

/*gen occ2=1 if (class8==4| class8==8) & class8!=. //1=production workers, service workers; 0=other 
replace occ2=0 if class8!=4 & class8!=8 & class8!=.
label variable occ2 "1=production workers, service workers" 

gen occ3=1 if class8==7 & class8!=. // 1=socio-cultural professionals
replace occ3=0 if class8!=7 & class8!=.
label variable occ3 "1=socio-cultural professionals" 

gen occ4=1 if (class8==7| class8==5) & class8!=.
replace occ4=0 if (class8==1|class8==2|class8==3|class8==4|class8==6|class8==8 ) & occ4==.
label variable occ4 "1=socio-cultural professionals and managers"

gen religio3=1 if rlgatnd<5 // monthly churchgoers
replace religio3=0 if rlgatnd>4 & rlgatnd!=.
label variable religio3 "monthly churchgoers"
label define religio3 0 "never" 1 "monthly or more frequent", replace
label values religio3 religio3

gen religio4=1 if rlgatnd<7 // broadest church
replace religio4=0 if rlgatnd==7 & rlgatnd!=.
label variable religio4 "broadest church"
label define religio4 0 "never" 1 "rarely/sometimes/frequent", replace
label values religio4 religio4

gen religio6=1 if rlgatnd<4 // weekly+sometimes church
replace religio6=0 if rlgatnd>3 & rlgatnd<=7 & rlgatnd!=.
label variable religio6 "weekly church"
label define religio6 0  "<once a week/never" 1 "weekly or more"
label values religio6 religio6

gen led=1 if (edulvla==1|edulvla==2) & edulvla!=. // 1=less than lower or lower secondary completed, 0 = higher
replace led=0 if edulvla>2 & edulvla!=.
replace led=1 if (edulvlb==0 | edulvlb==1) & edulvlb!=. & essround==8
replace led=0 if edulvlb>1 & edulvlb!=. &  essround==8
label variable led "1=less than lower or lower secondary completed" 
*/

**************
gen occ2_dif100=occ2_dif*100 // production and service
label variable occ2_dif100 "production and service workers"
gen occ3_dif100=occ3_dif*100 // socio-professionals
label variable occ3_dif100 "socioprofessionals"
gen occ4_dif100=occ4_dif*100 // socio-profs and managers
label variable occ4_dif100 "socioprofessionals or managers"

gen led_dif100=led_dif*100 // lower educated (less than lower or lower secondary completed
label variable led_dif100 "lower secondary completed or less"

gen monthly_dif100=religio3_dif100 // monthly churchgoers -- available only for ESS
label variable monthly_dif100 "monthly churchgoers (or more frequent)"

gen secular1_dif=religio4_dif*(-1) // decidedly secular voters  -- available for EES
gen secular1_dif100=secular1_dif*100
label variable secular1_dif100 "decidedly secular (never church)"

****************
reg occ2_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(INDUSTRIAL & SERVICE WORKERS) saving(occ2vote.gph, replace)

reg occ4_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(SOCIO-PROFESSIONALS) saving(occ4vote.gph, replace)

reg monthly_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))

reg secular1_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-40(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(SECULAR PEOPLE) saving(secularvote.gph, replace)

reg led_dif100 ib5.family6##ib2.vote_dich10 ENEP turnout i.country i.year if family2!=8 & family2!=11 & family2!=9 & max_n>30 & (EBESSEES==2) & year>2000, cl(party_id)
margins, at (family6=(1 2 3 4 5 6) vote_dich10=(1 2))
mplotoffset, offset(0.2) recast(scatter) ytitle(P-score) ylabel(-20(10)20, labsize(medsmall) angle(horizontal) format(%9.1g) grid) ///
title(LOWER EDUCATED) saving(lowedvote.gph, replace)

grc1leg occupvote.gph occ2vote.gph occ4vote.gph , leg(occupvote.gph) pos(6) span cols(1) // FIGURE E.2

grc1leg religiovoteESS.gph secularvote.gph eduvoteESS.gph lowedvote.gph, leg(eduvoteESS.gph) pos(6) span cols(2) // FIGURE E.3




